function paymentIndexLoad(){
  $("#menuPaymentCash").click(
    function(e){
      menuSelect("#paymentMenuBar",this);
      $.get(this.href,{},
        function(content){
          $("#ajMain").show().html(content);
          $("#ajContactPanel").hide();
          $("#ajContactForm").remove();
          contactDialogMode=20;
        }
      );
      e.preventDefault();
    }
  );
  $("#menuPaymentCheck").click(
    function(e){
      menuSelect("#paymentMenuBar",this);
      $.get(this.href,{},
        function(content){
          $("#ajMain").show().html(content);
          $("#ajContactPanel").hide();
          $("#ajContactForm").remove();
          contactDialogMode=21;
        }
      );
      e.preventDefault();
    }
  );
  $("#menuPaymentOffset").click(
    function(e){
      menuSelect("#paymentMenuBar",this);
      $.get(this.href,{},
        function(content){
          $("#ajMain").show().html(content);
          $("#ajContactPanel").hide();
          $("#ajContactForm").remove();
          contactDialogMode=22;
        }
      );
      e.preventDefault();
    }
  );
  $("#menuPaymentSearch").click(
    function(e){
      menuSelect("#paymentMenuBar",this);
      $.get(this.href,{},
        function(content){
          $("#ajMain").show().html(content);
          $("#ajContactPanel").hide();
          $("#ajContactForm").remove();
        }
      );
      e.preventDefault();
    }
  );
}

function paymentNewSetup(){
  $("#formPayment").submit(
    function(){
      showStatusWindow();
      
      $(this).ajaxSubmit(
        {
          type: 'post',
          dataType: 'html',
          success: 
            function(data,statusText){
              $('#ajPaymentPanel').html(data);
              hideStatusWindow();
            },
        }
      );
      
      return false;
    }
  );
}

function paymentSetupSearch(){
  $("#formPaymentSearch").submit(
    function(){
      showStatusWindow();
      
      $(this).ajaxSubmit(
        {
          type: 'post',
          dataType: 'html',
          success: 
            function(data,statusText){
              $('#ajPaymentGrid').html(data);
              $("#ajPaymentForm").remove();
              $("#ajPaymentPanel").hide();
              $("#ajPaymentGrid").show();
              $('#ajPaymentShowGrid').hide();
              hideStatusWindow();
            },
        }
      );
      
      return false;
    }
  );
  
  $("#ajPaymentShowGrid").click(
    function(e){
      $(this).hide();
      $("#ajPaymentForm").remove();
      $("#ajPaymentPanel").hide();
      $("#ajPaymentGrid").show();
      $(this).hide();
    }
  );
  
}

function paymentSetupCheckPanel(){
  $("#linkPaymentAddCheck").click(
    function(e){
      $.get(this.href,{},
        function(content){
          $('#ajPaymentChecksPanel').show().html(content);
        }
      );
      e.preventDefault();
    }
  );
  
}

function paymentVerifyDeleteCheck(payment_iden,check_iden){
      $.getJSON(
        'payment/verifyCheckDelete',
        {
          "payment_iden":payment_iden,
          "check_iden":check_iden,
        },
        function(data){
          if(data.success)
            $.get('actionVerifier/verify',
              {
                "task":"paymentCheckDelete",
                "payment_iden":data.payment_iden,
                "check_iden":data.check_iden,
                "cancel_callback":"paymentDeleteCheck({\"payment_iden\":\""+data.payment_iden+"\"})",
                "callback":"paymentDeleteCheck",
                "prompt":"Delete check payment: \""+data.check_id+"\" with amount "+data.amount+".",
              },
              function(content){
                $('#ajPaymentChecksPanel').html(content);
              }
            );
          else
            $.get('payment/showChecks',
              {
                "payment_iden":data.payment_iden,
                "message":data.message,
              },
              function(content){
                $('#ajPaymentChecksPanel').html(content);
              }
            );
        }
      );
      return false;
}




function paymentSetupCheckForm(payment_iden){
  $("#formChecksPayment").submit(
    function(){
      showStatusWindow();
      
      $(this).ajaxSubmit(
        {
          type: 'post',
          dataType: 'html',
          success: 
            function(data,statusText){
              $('#ajPaymentChecksPanel').html(data);
              hideStatusWindow();
            },
        }
      );
      
      return false;
    }
  );
  
  $("#buttonCancelAddCheck").click(
    function(){
      showStatusWindow();
      $.get(
        'payment/showChecks',
        {"payment_iden":payment_iden},
        function(content){
          hideStatusWindow();
          $('#ajPaymentChecksPanel').html(content);
        }
      );
    }
  );
  
}

function paymentDeleteCheck(data){
  $.get(
    'payment/showChecks',
    data,
    function(content){
      hideStatusWindow();
      $('#ajPaymentChecksPanel').html(content);
    }
  );
}

function paymentAddInvoice(){
  $('#paymentLinkAddInvoice').click(
    function(e){
      $.get(this.href,{},
        function(content){
          $('#ajPaymentInvoicePanel').html(content);
        }
      );
      e.preventDefault();
    }
  );
}

function paymentAddSelectInvoice(invoice_id,total,invoice_iden){
  $('#labelPaymentInvoiceNumber').html(invoice_id); 
  $('#payment_invoice_amount').val(total); 
  $('#payment_invoice_invoice_iden').val(invoice_iden);
}


function paymentDeleteInvoice(data){
  $.get(
    'payment/showInvoices',
    data,
    function(content){
      hideStatusWindow();
      $('#ajPaymentInvoicePanel').html(content);
    }
  );
}

function paymentVoidSuccess(data,statusText){
  $.get(
    'payment/edit',
    data,
    function(content){
      $('#ajPaymentPanel').html(content);
    }
  );
  paymentGetGridRowData(data.payment_iden);
  hideStatusWindow();
}

function paymentGetGridRowData(payment_iden){
  $.get(
    'payment/getGridTd',{'payment_iden':payment_iden},
    function(content){
      $('#row_payment_'+payment_iden).html(content);
    }
  );
}